package com.franklin.ideaplugin.easytesting.ui.history;

import cn.hutool.core.date.DateUtil;
import com.franklin.ideaplugin.api.ui.tree.BaseSimpleNode;
import com.franklin.ideaplugin.easytesting.common.entity.ETRsp;
import com.franklin.ideaplugin.easytesting.entity.ExecuteResult;
import com.intellij.icons.AllIcons;
import com.intellij.openapi.util.NlsSafe;
import com.intellij.psi.PsiMethod;
import com.intellij.ui.treeStructure.SimpleNode;

import javax.swing.*;
import java.util.Collections;
import java.util.Date;
import java.util.List;

/**
 * 历史节点
 *
 * @author Ye Junhui
 * @since 2023/6/21
 */
public class HistoryNode extends BaseSimpleNode<HistoryNode> {

    private PsiMethod interfaceClassName;
    private ExecuteResult executeResult;

    protected HistoryNode(SimpleNode aParent,PsiMethod interfaceClassName, ExecuteResult executeResult) {
        super(aParent);
        this.interfaceClassName = interfaceClassName;
        this.executeResult =  executeResult;
    }


    @Override
    protected SimpleNode[] buildChildren() {
        return new SimpleNode[0];
    }

    @Override
    public @NlsSafe String getName() {
        return DateUtil.formatDateTime(new Date(this.executeResult.getExecuteTime()));
    }

    /**
     * 自定义图标
     * @return
     */
    @Override
    public Icon getMyIcon(){
        if (this.executeResult.isSuccess()){
            return AllIcons.RunConfigurations.TestState.Green2;
        }
        return AllIcons.RunConfigurations.TestState.Red2;
    }

    public ExecuteResult getExecuteResult() {
        return executeResult;
    }
}
